# -*- coding: utf-8 -*-

# Define here the models for your scraped items
#
# See documentation in:
# https://docs.scrapy.org/en/latest/topics/items.html

import scrapy
from scrapy.loader.processors import TakeFirst
from scrapy.loader.processors import MapCompose
import re
# def re_stock(array):
#     res = re.search('\d+', array)
#     result = res.group()
#     return result
class ToscrapebookItem(scrapy.Item):
    # define the fields for your item here like:
    # name = scrapy.Field()
    bookname = scrapy.Field(
        input_processor = MapCompose(lambda x:x.strip("\"")),
        output_processor = TakeFirst()
    )
    bookprice = scrapy.Field(
        input_processor = MapCompose(lambda x:x.replace('£','')),
        output_processor = TakeFirst()
    )
    bookstock = scrapy.Field(
        # input_processor=MapCompose(re_stock),
        input_processor = MapCompose(lambda x:re.search('\d+', x).group()),
        output_processor = TakeFirst()
    )